package com.bqtt.tumor.demo.business;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bqtt.tumor.demo.common.MyBeanFactory;
import com.bqtt.tumor.demo.data_access.FeatureDAO;
import com.bqtt.tumor.demo.entity.DiagnosisMethod;
import com.bqtt.tumor.demo.entity.Feature;
import com.bqtt.tumor.demo.entity.TreatmentMethod;

public class FeatureService {

	
	private static FeatureDAO featureDAO = (FeatureDAO) MyBeanFactory.getBean("featureDAO");
	private static Logger log = LoggerFactory.getLogger(FeatureService.class);
	
	public static List<Feature> searchByCondition(Feature condition,int pageSize,int pageNo)
	{
		
		List<Feature> result = featureDAO.fuzzyFindByProperties(condition.getSQLValidAttributes(),pageSize,pageNo);

		return result;
	}
	
	public static List<Feature> getList()
	{
		return featureDAO.findAll();
	}
	
	
	public static List<Feature> getList(int ... category)
	{
		List<Feature> temp = new ArrayList<Feature>();
		for(int item:category)
		{
			temp.addAll(featureDAO.findByProperty("category", item));
		}
		return temp;
	}
	

	public static List<Feature> getFeaturesByIds(List<Integer> ids)
	{
		List<Feature>  result = new ArrayList<Feature>();
		
		for(Integer item:ids)
		{
			result.add(featureDAO.findById(item));
		}
		return result;
	}
	
	public static Feature getFeatureById(Integer id)
	{
		return featureDAO.findById(id);
	}
	
	
	public static Feature getFeatureInfoById(Integer id)
	{
		return featureDAO.findById(id);
	}
	
	public static List<Feature> searchByCondition(Feature condition,int pageSize,int pageNo,long id)
	{
		
		List<Feature> result = featureDAO.fuzzyFindByProperties(condition.getSQLValidAttributes(),pageSize,pageNo);
		
		for(Feature item:result)
		{
			if(item.getFeature_id()==id)
			{
				item.setDisplayName("inline-block");
			}
			item.fillStringField();
		}
		return result;
	}
	
	public static boolean add(Feature obj)
	{
		try
		{
			featureDAO.save(obj);
			return true;
		}
		catch(Exception e)
		{
			log.error(e.getMessage());
	     	return false;	
		}
		
	}
	
	public static boolean update(Feature obj)
	{
		try
		{
			 
			if(obj.getFeature_id()>0)
			{
				featureDAO.update(obj);
				return true;
			}
			else
				
			return false;
		}
		catch(Exception e)
		{
			log.error(e.getMessage());
	     	return false;	
		}
		
	}
	
	
}
